using System;
using System.Collections.Generic;
using System.Text;

namespace Acms.DataControls
{
    public class UpdateDataEventArgs<TItem> : UpdatingDataEventArgs<TItem>
    {
        public UpdateDataEventArgs(TItem item, UpdateAction action, System.Collections.IDictionary keys, System.Collections.IDictionary values, System.Collections.IDictionary oldValues)
            : base(item, action, keys, values, oldValues)
        {
            
        }

        private int changes;
        public int Changes
        {
            get { return changes; }
            set { changes = value; }
        }

    }

    public class UpdatingDataEventArgs<TItem> : System.EventArgs
    {
        public UpdatingDataEventArgs(TItem item, UpdateAction action, System.Collections.IDictionary keys, System.Collections.IDictionary values, System.Collections.IDictionary oldValues)
        {
            this.item = item;
            this.action = action;
            this.keys = keys;
            this.values = values;
            this.oldValues = oldValues;
        }

        private TItem item;
        public TItem Item
        {
            get { return item; }
        }

        private UpdateAction action;
        public UpdateAction Action
        {
            get { return action; }
        }

        private System.Collections.IDictionary keys;
        private System.Collections.IDictionary values;
        private System.Collections.IDictionary oldValues;

        public T GetKeyValue<T>(string key)
        {
            return GenericDataSource<TItem>.GetValue<T>(key, keys);
        }

        public T GetNewValue<T>(string key)
        {
            return GenericDataSource<TItem>.GetValue<T>(key, values);
        }

        public T GetOldValue<T>(string key)
        {
            return GenericDataSource<TItem>.GetValue<T>(key, oldValues);
        }

        public bool ValueChanged<T>(string key)
        {
            if (values == null || oldValues == null)
            {
                return false;
            }
            else
            {
                return GenericDataSource<TItem>.ValueChanged<T>(key, values, oldValues);
            }
        }

        public bool HasChanged()
        {
            foreach (string key in values.Keys)
            {
                if(ValueChanged<object>(key))
                    return true;
            }
            return false;
        }

    }
}